import 'package:flutter_test/flutter_test.dart';
import 'package:flowplan_app/core/offline/offline_data_manager.dart';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  group('离线操作记录测试', () {
    late OfflineOperation operation;

    setUp(() {
      // 创建一个测试用的离线操作记录
      operation = OfflineOperation(
        id: 'test_operation_1',
        entityType: 'note',
        operationType: OfflineOperationType.create,
        data: {
          'title': '测试笔记',
          'content': '测试内容',
        },
        timestamp: DateTime.now(),
      );
    });

    test('离线操作记录创建测试', () {
      expect(operation, isNotNull);
      expect(operation.id, 'test_operation_1');
      expect(operation.entityType, 'note');
      expect(operation.operationType, OfflineOperationType.create);
      expect(operation.data['title'], '测试笔记');
    });

    test('离线操作记录序列化测试', () {
      final json = operation.toJson();
      expect(json['id'], 'test_operation_1');
      expect(json['entityType'], 'note');
      expect(json['operationType'], 'create');
      expect(json['data']['title'], '测试笔记');
    });

    test('离线操作记录反序列化测试', () {
      final json = operation.toJson();
      final deserialized = OfflineOperation.fromJson(json);
      expect(deserialized.id, operation.id);
      expect(deserialized.entityType, operation.entityType);
      expect(deserialized.operationType, operation.operationType);
      expect(deserialized.data['title'], operation.data['title']);
    });
  });

  group('离线数据管理器基本功能测试', () {
    late OfflineDataManager offlineDataManager;

    setUp(() {
      offlineDataManager = OfflineDataManager();
    });

    test('离线数据管理器实例化测试', () {
      expect(offlineDataManager, isNotNull);
    });
  });
}
